<!doctype html>



  


<html class="theme-next muse use-motion" lang="zh-Hans">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>









<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />




  
  
  
  

  
    
    
  

  

  

  

  

  
    
    
    <link href="//fonts.googleapis.com/css?family=Lato:300,300italic,400,400italic,700,700italic&subset=latin,latin-ext" rel="stylesheet" type="text/css">
  






<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.1.1" rel="stylesheet" type="text/css" />


  <meta name="keywords" content="Redis," />








  <link rel="shortcut icon" type="image/x-icon" href="/favicon.ico?v=5.1.1" />






<meta name="description" content="&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;redis是一个key-value存储系统，官方站点 &amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;和memcached类似，但支持数据持久化 &amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;支持更多val">
<meta name="keywords" content="Redis">
<meta property="og:type" content="article">
<meta property="og:title" content="Redis下载安装">
<meta property="og:url" content="https://hcldirgit.github.io/2017/09/03/Redis/1. Redis下载安装/index.html">
<meta property="og:site_name" content="失落的乐章">
<meta property="og:description" content="&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;redis是一个key-value存储系统，官方站点 &amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;和memcached类似，但支持数据持久化 &amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;支持更多val">
<meta property="og:locale" content="zh-Hans">
<meta property="og:image" content="https://github.com/hcldirgit/image/blob/master/redis%E4%B8%8B%E8%BD%BD%E5%AE%89%E8%A3%85/01.png?raw=true">
<meta property="og:image" content="https://github.com/hcldirgit/image/blob/master/redis%E4%B8%8B%E8%BD%BD%E5%AE%89%E8%A3%85/02.png?raw=true">
<meta property="og:image" content="https://github.com/hcldirgit/image/blob/master/redis%E4%B8%8B%E8%BD%BD%E5%AE%89%E8%A3%85/03.png?raw=true">
<meta property="og:image" content="https://github.com/hcldirgit/image/blob/master/redis%E4%B8%8B%E8%BD%BD%E5%AE%89%E8%A3%85/04.png?raw=true">
<meta property="og:image" content="https://github.com/hcldirgit/image/blob/master/redis%E4%B8%8B%E8%BD%BD%E5%AE%89%E8%A3%85/05.png?raw=true">
<meta property="og:image" content="https://github.com/hcldirgit/image/blob/master/redis%E4%B8%8B%E8%BD%BD%E5%AE%89%E8%A3%85/06.png?raw=true">
<meta property="og:image" content="https://github.com/hcldirgit/image/blob/master/redis%E4%B8%8B%E8%BD%BD%E5%AE%89%E8%A3%85/07.png?raw=true">
<meta property="og:image" content="https://github.com/hcldirgit/image/blob/master/redis%E4%B8%8B%E8%BD%BD%E5%AE%89%E8%A3%85/08.png?raw=true">
<meta property="og:image" content="https://github.com/hcldirgit/image/blob/master/redis%E4%B8%8B%E8%BD%BD%E5%AE%89%E8%A3%85/09.png?raw=true">
<meta property="og:image" content="https://github.com/hcldirgit/image/blob/master/redis%E4%B8%8B%E8%BD%BD%E5%AE%89%E8%A3%85/10.png?raw=true">
<meta property="og:image" content="https://github.com/hcldirgit/image/blob/master/redis%E4%B8%8B%E8%BD%BD%E5%AE%89%E8%A3%85/11.png?raw=true">
<meta property="og:updated_time" content="2017-09-02T17:30:33.628Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="Redis下载安装">
<meta name="twitter:description" content="&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;redis是一个key-value存储系统，官方站点 &amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;和memcached类似，但支持数据持久化 &amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;支持更多val">
<meta name="twitter:image" content="https://github.com/hcldirgit/image/blob/master/redis%E4%B8%8B%E8%BD%BD%E5%AE%89%E8%A3%85/01.png?raw=true">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Muse',
    sidebar: {"position":"left","display":"post","offset":12,"offset_float":0,"b2t":false,"scrollpercent":false},
    fancybox: true,
    motion: true,
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="https://hcldirgit.github.io/2017/09/03/Redis/1. Redis下载安装/"/>





  <title>Redis下载安装 | 失落的乐章</title>
</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  




<script>
  (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
            (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
          m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  })(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
  ga('create', '85*****1', 'auto');
  ga('send', 'pageview');
</script>


  <script type="text/javascript">
    var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "https://hm.baidu.com/hm.js?87980c**************99ec5e26fb5";
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
  </script>











  
  
    
  

  <div class="container sidebar-position-left page-post-detail ">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">失落的乐章</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle">技术面前，永远都是学生。</p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br />
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-message">
          <a href="/message" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-external-link"></i> <br />
            
            留言
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">
    <link itemprop="mainEntityOfPage" href="https://hcldirgit.github.io/2017/09/03/Redis/1. Redis下载安装/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="失落的乐章">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/0.png">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="失落的乐章">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">Redis下载安装</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2017-09-03T02:09:22+08:00">
                2017-09-03
              </time>
            

            

            
          </span>

          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    <div class="post-body" itemprop="articleBody">

      
      

      
        <p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;redis是一个key-value存储系统，<a href="http://redis.io" target="_blank" rel="external">官方站点</a></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;和memcached类似，但支持数据持久化</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;支持更多value类型，除了和string外，还支持hash、lists（链表）、sets（集合）和sorted sets（有序集合）几种数据类型</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;redis使用了两种文件格式：全量数据（RDB）和增量请求（aof)。全量数据格式是 把内存中的数据写入磁盘，便于下次读取文件进行加载。增量请求文件则是把内存中的 数据序列化为操作请求，用于读取文件进行replay得到数据redis的存储分为内存存储、    磁盘存储和log文件三部分</p>
<h2 id="1-redis-安装"><a href="#1-redis-安装" class="headerlink" title="1.redis 安装"></a>1.redis 安装</h2><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<a href="http://redis.io/download" target="_blank" rel="external">官网下载地址</a></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;下载 redis</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@redis ~]<span class="comment"># wget http://download.redis.io/releases/redis-3.2.8.tar.gz</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;解压</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@redis ~]<span class="comment"># tar zxvf redis-3.2.8.tar.gz</span></div></pre></td></tr></table></figure>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@redis ~]<span class="comment"># cd redis-3.2.8</span></div></pre></td></tr></table></figure>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@redis redis-3.2.8]<span class="comment"># yum install -y gcc epel-release</span></div></pre></td></tr></table></figure>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@redis redis-3.2.8]<span class="comment"># yum install -y jemalloc-devel</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;编译</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@redis redis-3.2.8]<span class="comment"># make</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;如果出错，运行如下命令：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">[root@redis redis-3.2.8]<span class="comment"># cd deps/</span></div><div class="line">[root@redis deps]<span class="comment"># make hiredis lua jemalloc linenoise/</span></div></pre></td></tr></table></figure>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">[root@redis deps]<span class="comment"># cd ..</span></div><div class="line">[root@redis redis-3.2.8]<span class="comment"># make</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;安装</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@redis redis-3.2.8]<span class="comment"># make PREFIX=/usr/local/redis install</span></div></pre></td></tr></table></figure>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@redis redis-3.2.8]<span class="comment"># mkdir /usr/local/redis/etc</span></div></pre></td></tr></table></figure>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@redis ~]<span class="comment"># wget http://www.apelearn.com/study_v2/.redis_conf -O /usr/local/redis/etc/redis.conf 2&gt;/dev/null</span></div></pre></td></tr></table></figure>
<h3 id="redis-启动脚本"><a href="#redis-启动脚本" class="headerlink" title="redis 启动脚本"></a>redis 启动脚本</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@redis ~]<span class="comment"># wget http://www.apelearn.com/study_v2/.redis_init -O /etc/init.d/redis 2&gt;/dev/null</span></div></pre></td></tr></table></figure>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div></pre></td><td class="code"><pre><div class="line">[root@redis ~]<span class="comment"># useradd -s /sbin/nologin redis</span></div><div class="line">[root@redis ~]<span class="comment"># mkdir /usr/local/redis/var</span></div><div class="line">[root@redis ~]<span class="comment"># chmod 777 /usr/local/redis/var</span></div><div class="line">[root@redis ~]<span class="comment"># chmod 755 /etc/init.d/redis</span></div><div class="line">[root@redis ~]<span class="comment"># chkconfig --add redis</span></div><div class="line">[root@redis ~]<span class="comment"># chkconfig redis on</span></div><div class="line">[root@redis ~]<span class="comment"># service redis start</span></div><div class="line">启动 ：                              [确定]</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<a href="https://hcldirgit.github.io/2017/08/25/Redis/24.%20redis%20%E9%85%8D%E7%BD%AE/">redis 配置</a></p>
<h2 id="2-redis-数据结构"><a href="#2-redis-数据结构" class="headerlink" title="2.redis 数据结构"></a>2.redis 数据结构</h2><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<a href="https://hcldirgit.github.io/2017/08/25/Redis/25.%20Redis%20%E6%95%B0%E6%8D%AE%E7%B1%BB%E5%9E%8B/">Redis 数据类型</a></p>
<h3 id="redis-数据类型-string"><a href="#redis-数据类型-string" class="headerlink" title="redis 数据类型 - string"></a>redis 数据类型 - string</h3><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;string是最简单的类型，你可以理解成与Memcached一样的类型，一个key对应一个value，其上支持的操作与Memcached的操作类似，它的功能更丰富。设置可以存二进制的对象。</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;示例：</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;首先</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">[root@redis ~]<span class="comment"># alias redis-cli='/usr/local/redis/bin/redis-cli'</span></div><div class="line">[root@redis ~]<span class="comment"># vim .bashrc</span></div></pre></td></tr></table></figure>
<p><img src="https://github.com/hcldirgit/image/blob/master/redis%E4%B8%8B%E8%BD%BD%E5%AE%89%E8%A3%85/01.png?raw=true" alt="01"></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;这样就可以直接使用 redis-cli 命令，或者编辑 profile </p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@redis ~]<span class="comment"># redis-cli set mykey "yanyi.com"</span></div></pre></td></tr></table></figure>
<p><img src="https://github.com/hcldirgit/image/blob/master/redis%E4%B8%8B%E8%BD%BD%E5%AE%89%E8%A3%85/02.png?raw=true" alt="02"></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@redis ~]<span class="comment"># redis-cli get mykey</span></div></pre></td></tr></table></figure>
<p><img src="https://github.com/hcldirgit/image/blob/master/redis%E4%B8%8B%E8%BD%BD%E5%AE%89%E8%A3%85/03.png?raw=true" alt="03"></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@redis ~]<span class="comment"># redis-cli</span></div></pre></td></tr></table></figure>
<p><img src="https://github.com/hcldirgit/image/blob/master/redis%E4%B8%8B%E8%BD%BD%E5%AE%89%E8%A3%85/04.png?raw=true" alt="04"></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div></pre></td><td class="code"><pre><div class="line">127.0.0.1:6379&gt; mset key1 1 key2 a key3 c </div><div class="line">OK</div><div class="line">127.0.0.1:6379&gt; mget key1 key2 key3</div><div class="line">1) <span class="string">"1"</span></div><div class="line">2) <span class="string">"a"</span></div><div class="line">3) <span class="string">"c"</span></div></pre></td></tr></table></figure>
<p><img src="https://github.com/hcldirgit/image/blob/master/redis%E4%B8%8B%E8%BD%BD%E5%AE%89%E8%A3%85/05.png?raw=true" alt="05"></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<a href="https://hcldirgit.github.io/2017/08/24/Redis/18.%20Redis%20%E5%AD%97%E7%AC%A6%E4%B8%B2(String">Redis 字符串(String)</a>/)</p>
<h3 id="redis-数据类型-list"><a href="#redis-数据类型-list" class="headerlink" title="redis 数据类型 - list"></a>redis 数据类型 - list</h3><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;list是一个链表结构，主要功能是push、pop、获取一个范围的所有值等等。操作中key理解为链表的名字。使用 List 结构，我们可以轻松地实现最新消息排行等功能（比如新浪微博的 TimeLine ）。list 的另一个应用就是消息队列，可以利用 list 的 push操作，将任务存在 list 中，然后工作线程再用pop操作将任务取出进行执行。</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;示例：</p>
<p><img src="https://github.com/hcldirgit/image/blob/master/redis%E4%B8%8B%E8%BD%BD%E5%AE%89%E8%A3%85/06.png?raw=true" alt="06"></p>
<p><img src="https://github.com/hcldirgit/image/blob/master/redis%E4%B8%8B%E8%BD%BD%E5%AE%89%E8%A3%85/07.png?raw=true" alt="07"></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<a href="https://hcldirgit.github.io/2017/08/24/Redis/20.%20Redis%20%E5%88%97%E8%A1%A8(List">Redis 列表(List)</a>/)</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;注： <a href="https://hcldirgit.github.io/2017/08/24/Redis/7.%20Redis%20list%20%E4%B9%8B%E5%A2%9E%E5%88%A0%E6%94%B9%E6%9F%A5/">Redis list 之增删改查</a></p>
<h3 id="redis-数据类型-set"><a href="#redis-数据类型-set" class="headerlink" title="redis 数据类型 - set"></a>redis 数据类型 - set</h3><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;set是集合，和我们数学中的集合概念相似，对集合的操作有添加删除元素，有对多个集合求交并差等操作。操作中key理解为集合的名字。比如在微博应用中，可以将一个用户所有的关注人存在一个集合中，将其所有粉丝存在一个集合。因为 Redis 非常人性化的为集合提供了求交集、并集、差集等操作，那么就可以非常方便的实现如共同关注、共同喜好、二度好友等功能，对上面的所有集合操作，你还可以使用不同的命令选择将结果返回给客户端还是存集到一个新的集合中。QQ有一个社交功能叫做“好友标签”，大家可以给你的好友贴标签，比如“大美女”、“土豪”、“欧巴”等等，这时就可以使用redis的集合来实现，把每一个用户的标签都存储在一个集合之中。</p>
<p><img src="https://github.com/hcldirgit/image/blob/master/redis%E4%B8%8B%E8%BD%BD%E5%AE%89%E8%A3%85/08.png?raw=true" alt="08"></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<a href="https://hcldirgit.github.io/2017/08/24/Redis/21.%20Redis%20%E9%9B%86%E5%90%88(Set">Redis 集合(Set)</a>/)</p>
<h3 id="redis-数据类型-sort-set"><a href="#redis-数据类型-sort-set" class="headerlink" title="redis 数据类型 - sort set"></a>redis 数据类型 - sort set</h3><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;sorted set是有序集合，它比set多了一个权重参数score，使得集合中的元素能够按 score 进行有序排列，比如一个存储全班同学成绩的 Sorted Sets，其集合 value 可以是同学的学号，而 score 就可以是其考试得分，这样在数据插入集合的时候，就已经进行了天然的排序。</p>
<p><img src="https://github.com/hcldirgit/image/blob/master/redis%E4%B8%8B%E8%BD%BD%E5%AE%89%E8%A3%85/09.png?raw=true" alt="09"></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;倒序 </p>
<p><img src="https://github.com/hcldirgit/image/blob/master/redis%E4%B8%8B%E8%BD%BD%E5%AE%89%E8%A3%85/10.png?raw=true" alt="10"></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<a href="https://hcldirgit.github.io/2017/08/24/Redis/22.%20Redis%20%E6%9C%89%E5%BA%8F%E9%9B%86%E5%90%88(sorted%20set">Redis 有序集合(sorted set)</a>/)</p>
<h3 id="redis-数据类型-hash"><a href="#redis-数据类型-hash" class="headerlink" title="redis 数据类型 - hash"></a>redis 数据类型 - hash</h3><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;在 Memcached 中，我们经常将一些结构化的信息打包成 hashmap，在客户端序列化后存储为一个字符串的值（一般是 JSON 格式），比如用户的昵称、年龄、性别、积分等。</p>
<p><img src="https://github.com/hcldirgit/image/blob/master/redis%E4%B8%8B%E8%BD%BD%E5%AE%89%E8%A3%85/11.png?raw=true" alt="11"></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<a href="https://hcldirgit.github.io/2017/08/24/Redis/19.%20Redis%20%E5%93%88%E5%B8%8C(Hash">Redis 哈希(Hash)</a>/)</p>
<h2 id="3-redis持久化"><a href="#3-redis持久化" class="headerlink" title="3.redis持久化"></a>3.redis持久化</h2><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;Redis提供了两种持久化的方式，分别是RDB（Redis DataBase）和AOF（Append Only File）。</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;RDB，简而言之，就是在不同的时间点，将redis存储的数据生成快照并存储到磁盘等介质上。</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;AOF，则是换了一个角度来实现持久化，那就是将redis执行过的所有写指令记录下来，在下次redis重新启动时，只要把这些写指令从前到后再重复执行一遍，就可以实现数据恢复了。</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;其实RDB和AOF两种方式也可以同时使用，在这种情况下，如果redis重启的话，则会优先采用AOF方式来进行数据恢复，这是因为AOF方式的数据恢复完整度更高。</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;如果你没有数据持久化的需求，也完全可以关闭RDB和AOF方式，这样的话，redis将变成一个纯内存数据库，就像memcache一样。</p>

      
    </div>

    <div>
      
        

      
    </div>

    <div>
      
        

      
    </div>

    <div>
      
        

      
    </div>

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/Redis/" rel="tag"># Redis</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2017/09/03/Puppet/4. Puppet exec/" rel="next" title="Puppet exec">
                <i class="fa fa-chevron-left"></i> Puppet exec
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2017/09/03/Redis/10. Redis快速入门/" rel="prev" title="Redis快速入门">
                Redis快速入门 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          
  <div class="comments" id="comments">
    
  </div>


        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap" >
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
          <img class="site-author-image" itemprop="image"
               src="/images/0.png"
               alt="失落的乐章" />
          <p class="site-author-name" itemprop="name">失落的乐章</p>
           
              <p class="site-description motion-element" itemprop="description">失落的乐章的Blog</p>
          
        </div>
        <nav class="site-state motion-element">

          
            <div class="site-state-item site-state-posts">
              <a href="/">
                <span class="site-state-item-count">627</span>
                <span class="site-state-item-name">日志</span>
              </a>
            </div>
          

          

          
            
            
            <div class="site-state-item site-state-tags">
              <a href="/tags/index.html">
                <span class="site-state-item-count">38</span>
                <span class="site-state-item-name">标签</span>
              </a>
            </div>
          

        </nav>

        

        <div class="links-of-author motion-element">
          
            
              <span class="links-of-author-item">
                <a href="https://github.com/hcldirgit" target="_blank" title="GitHub">
                  
                    <i class="fa fa-fw fa-github"></i>
                  
                  GitHub
                </a>
              </span>
            
          
        </div>

        
        

        
        

        


      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#1-redis-安装"><span class="nav-number">1.</span> <span class="nav-text">1.redis 安装</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#redis-启动脚本"><span class="nav-number">1.1.</span> <span class="nav-text">redis 启动脚本</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2-redis-数据结构"><span class="nav-number">2.</span> <span class="nav-text">2.redis 数据结构</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#redis-数据类型-string"><span class="nav-number">2.1.</span> <span class="nav-text">redis 数据类型 - string</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#redis-数据类型-list"><span class="nav-number">2.2.</span> <span class="nav-text">redis 数据类型 - list</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#redis-数据类型-set"><span class="nav-number">2.3.</span> <span class="nav-text">redis 数据类型 - set</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#redis-数据类型-sort-set"><span class="nav-number">2.4.</span> <span class="nav-text">redis 数据类型 - sort set</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#redis-数据类型-hash"><span class="nav-number">2.5.</span> <span class="nav-text">redis 数据类型 - hash</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#3-redis持久化"><span class="nav-number">3.</span> <span class="nav-text">3.redis持久化</span></a></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright" >
  
  &copy; 
  <span itemprop="copyrightYear">2017</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">失落的乐章</span>
</div>


<div class="powered-by">
  由 <a class="theme-link" href="https://hexo.io">Hexo</a> 强力驱动
</div>

<div class="theme-info">
  主题 -
  <a class="theme-link" href="https://github.com/iissnan/hexo-theme-next">
    NexT.Muse
  </a>
</div>


        

        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  












  
  <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>

  
  <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>

  
  <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.1"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.1"></script>



  
  

  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.1"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.1"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.1"></script>



  


  




	





  





  





  






  





  

  

  

  

  

  

</body>
</html>
